import java.util.Random;
import java.util.concurrent.*;

public class DAY0105 {
    //Java 标准库线程池的创建方式总共有几种？
    // 分别使用代码创建并演示一下
    public static void main(String[] args) {
        ExecutorService pool = Executors.newCachedThreadPool();
//        ExecutorService pool1 = Executors.newFixedThreadPool(10);
//        ExecutorService pool2 = Executors.newSingleThreadExecutor();
//        ExecutorService pool3 = Executors.newScheduledThreadPool(1000);
//        ExecutorService pool4 = Executors.newSingleThreadScheduledExecutor();
//        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
//        Executors.newWorkStealingPool();
//    MyThreadPool pool=new MyThreadPool(10);
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        });

    }
}
class MyThreadPool{
    private BlockingQueue<Runnable> queue=new LinkedBlockingQueue<>();

    public  MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread t=new Thread(()->{
               while(true){
                   try {
                       Runnable runnable= queue.take();
                       runnable.run();
                   } catch (InterruptedException e) {
                       throw new RuntimeException(e);
                   }
               }
            });
            t.start();
        }
    }
    public void submit(Runnable runnable){
        try{
        queue.put(runnable);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
